package com.lianzhihui.romeex.widget.dialog;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.adapter.CoinSelAdapter;
import com.lianzhihui.romeex.config.AppConstants;
import com.lianzhihui.romeex.inter.SelectListener;
import com.lianzhihui.romeex.ui.base.BaseDialog;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Description: 选择币种弹窗
 * Author: RAMON
 * CreateDate: 2020/11/6 2:27 PM
 * UpdateUser:
 * UpdateDate:
 * UpdateRemark:
 * Version:
 */
public class CoinSelDialog extends BaseDialog implements BaseQuickAdapter.OnItemClickListener {

    @BindView(R.id.tv_cancel)
    TextView tv_cancel;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    public CoinSelAdapter adapter;
    SelectListener listener;

    public CoinSelDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int provideViewId() {
        return R.layout.dialog_coin_sel_layout;
    }

    @Override
    protected void initView() {
        initRecyclerView();
    }

    public void setListener(SelectListener listener) {
        this.listener = listener;
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        listener.onSelect(position);
        dismiss();
    }

    private void initRecyclerView() {
        adapter = new CoinSelAdapter(AppConstants.System.coins);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        linearLayoutManager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(this);
    }

    @OnClick({R.id.tv_cancel})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_cancel:
                dismiss();
                break;
        }
    }

}
